package com.snj.wef.selfwedding;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.snj.lib.RankingHolder;
import com.snj.lib.WefmallHolder;
import com.snj.wef.R;


public class WefmallAdapter extends BaseAdapter {
	
	String tag = "RankingAdapter";
	
	Context context;
	int layout;
	
	
	ArrayList<WefmallItem> mWefmallList;
	
	LayoutInflater mInflater = null;
	
	
	public WefmallAdapter(Context _context, int _layout, ArrayList<WefmallItem> _newslist) {
		// TODO Auto-generated constructor stub
		
		this.context = _context;
		this.layout = _layout;
		this.mWefmallList = _newslist;
		
	}
	
	public void Insert(ArrayList<WefmallItem> mList)
	{
		mWefmallList.addAll(mList);
	}
	
	public void SetList(ArrayList<WefmallItem> mList)
	{
		mWefmallList = mList;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return mWefmallList.size();
	}

	public WefmallItem getItem(int position) {
		// TODO Auto-generated method stub
		return mWefmallList.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
	
		WefmallHolder holder = null;
		
		if(convertView == null)
		{
			mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(layout, parent, false);
			
			holder = new WefmallHolder();
			
			holder.img_title = (ImageView)convertView.findViewById(R.id.Img_itemtitle);
			holder.img_content = (ImageView)convertView.findViewById(R.id.img_itemcontent);
			holder.img_itemback = (ImageView)convertView.findViewById(R.id.img_itemback);
			
			convertView.setTag(holder);
		}
		else
		{
			holder = (WefmallHolder)convertView.getTag();
		}
		
		
		
		holder.img_title.setImageBitmap(mWefmallList.get(position).GetTitleImage());
		holder.img_content.setImageBitmap(mWefmallList.get(position).GetContentImg());

		switch(mWefmallList.get(position).GetColorcode())
		{
		case 0:
			holder.img_itemback.setImageResource(R.drawable.colorcode0);
			break;
		case 1:
			holder.img_itemback.setImageResource(R.drawable.colorcode1);
			break;
		case 2:
			holder.img_itemback.setImageResource(R.drawable.colorcode2);
			break;
		case 3:
			holder.img_itemback.setImageResource(R.drawable.colorcode3);
			break;
		case 4:
			holder.img_itemback.setImageResource(R.drawable.colorcode4);
			break;
		case 5:
			holder.img_itemback.setImageResource(R.drawable.colorcode5);
			break;
		case 6:
			holder.img_itemback.setImageResource(R.drawable.colorcode6);
			break;
		}
	
		
		
		return convertView;
	}
	
	
}
